*****This estimates fully flexible diff in diffs around the cutoffss and for the whole sample

global user "`c(username)'"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1  "$dirdata\Final data"
global dir2  "$dirdata\Results\graphs"
cd "$dir2"

use "$dir1\pooled_hh.dta", clear





****** Figure 6


** Exclude the 5obs for which we observe a -5 and -6 years (8th-7th graders).
keep if  tau>-5

*global covs "age spanish schooling hhmale nchild5 urban np   age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year i.year"
global covs "age_m spanish_m schooling_m hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year c.urban#i.year  i.year"
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

egen w_hoursw_head=rowtotal(w_hoursw_p w_hoursw_m)
g work_head=w_hoursw_head>0
replace work_head=. if work_m==. & work_p==.
areg work_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs  [w=factor]  if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle(Prob.) yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("")   title( Lower Access) saving(es1a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg work_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle(" ")   title( Higher Access) saving(es1b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore


global covs "age_p spanish_p schooling_p hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year  c.urban#i.year i.year"



areg work_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=., a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle(Prob) yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Lower Access) saving(es2a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg work_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Higher Access) saving(es2b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

grc1leg es1a.gph es1b.gph, cols(2) ycommon graphregion(color(white)) title(Females) saving(a1, replace)
grc1leg es2a.gph es2b.gph, cols(2) ycommon graphregion(color(white)) title(Males) saving(a2, replace)
grc1leg a1.gph a2.gph, cols(1) xcommon graphregion(color(white)) 
gr export Figure6.eps, replace



****** Figure 7



use "$dir1\pooled_hh.dta", clear

** Exclude the 5obs for which we observe a -5 and -6 years (8th-7th graders).
keep if  tau>-5

*global covs "age spanish schooling hhmale nchild5 urban np   age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year i.year"
global covs "age_m spanish_m schooling_m hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year c.urban#i.year  i.year"
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

egen w_hoursw_head=rowtotal(w_hoursw_p w_hoursw_m)
g work_head=w_hoursw_head>0
replace work_head=. if work_m==. & work_p==.
areg w_hoursw_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle(Hours/week) yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("")   title( Lower Access) saving(es1a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg w_hoursw_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle(" ")   title( Higher Access) saving(es1b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore


global covs "age_p spanish_p schooling_p hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year  c.urban#i.year i.year"



areg w_hoursw_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=., a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle(Hours/week) yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Lower Access) saving(es2a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg w_hoursw_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Higher Access) saving(es2b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

grc1leg es1a.gph es1b.gph, cols(2) ycommon graphregion(color(white)) title(Females) saving(a1, replace)
grc1leg es2a.gph es2b.gph, cols(2) ycommon graphregion(color(white)) title(Males) saving(a2, replace)
grc1leg a1.gph a2.gph, cols(1) xcommon graphregion(color(white)) 
gr export Figure7.eps, replace



**************************** Figure 8


cd "$dir2"

use "$dir1\pooled_hh.dta", clear

** Exclude the 5obs for which we observe a -5 and -6 years (8th-7th graders).
keep if  tau>-5

*global covs "age spanish schooling hhmale nchild5 urban np   age_sac  c.age_sac#i.year c.np#i.year i.departamento#i.year i.year"
global covs "age_m spanish_m schooling_m hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year c.urban#i.year  i.year"
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

egen w_hoursw_head=rowtotal(w_hoursw_p w_hoursw_m)
g work_head=w_hoursw_head>0
replace work_head=. if work_m==. & work_p==.
areg w_ylabor_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("$Bs.") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("")   title( Lower Access) saving(es1a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg w_ylabor_m tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle(" ")   title( Higher Access) saving(es1b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore


global covs "age_p spanish_p schooling_p hhmale nchild5 urban age_sac np c.age_sac#i.year c.np#i.year i.departamento i.departamento#i.year  c.urban#i.year i.year"



areg w_ylabor_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs   [w=factor]   if (min_schooling>=1 & min_schooling<9) & q_fpc2005<=2 & fpc2005!=., a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("$Bs.") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Lower Access) saving(es2a, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

areg w_ylabor_p tau_1 tau_2  tau_3 tau_4 tau_5 tau_7 tau_8 tau_9 tau_10 i.min_schooling   $covs  [w=factor]    if (min_schooling>=1 & min_schooling<9) & q_fpc2005>=3 & fpc2005!=. , a(departamento) cluster(municipio)
mat V=e(V)
preserve
clear
set obs 10
gen coef=.
replace coef=_b[tau_1] in 1
replace coef=_b[tau_2] in 2
replace coef=_b[tau_3] in 3
replace coef=_b[tau_4] in 4
replace coef=_b[tau_5] in 5
replace coef=0 in 6
replace coef=_b[tau_7] in 7
replace coef=_b[tau_8] in 8
replace coef=_b[tau_9] in 9
replace coef=_b[tau_10] in 10
gen sd2=.

replace sd2=V[1,1] in 1
replace sd2=V[2,2] in 2
replace sd2=V[3,3] in 3
replace sd2=V[4,4] in 4
replace sd2=V[5,5] in 5

replace sd2=0 in 6
replace sd2=V[6,6] in 7
replace sd2=V[7,7] in 8
replace sd2=V[8,8] in 9
replace sd2=V[9,9] in 10

gen year=.
replace year=-6 in 1
replace year=-5 in 2
replace year=-4 in 3
replace year=-3 in 4
replace year=-2 in 5
replace year=-1 in 6
replace year=0 in 7 
replace year=1 in 8 
replace year=2 in 9
replace year=3 in 10
g ub=coef+1.96*sqrt(sd2)
g lb=coef-1.96*sqrt(sd2)
tw scatter coef year  if year>-5, sort || rcap ub lb year  if year>-5, sort ytitle("") yline(0)   legend(order(1 "Coefficient" 2 "95% CI"))  xtitle("Time to treatment")   title( Higher Access) saving(es2b, replace) ylabel(#8) ylabel(,labsize(small)) xlabel(#9) graphregion(color(white)) xline(-1,lcolor(maroon) lpattern(dash))
restore

grc1leg es1a.gph es1b.gph, cols(2) ycommon graphregion(color(white)) title(Females) saving(a1, replace)
grc1leg es2a.gph es2b.gph, cols(2) ycommon graphregion(color(white)) title(Males) saving(a2, replace)
grc1leg a1.gph a2.gph, cols(1) xcommon graphregion(color(white)) 
gr export Figure8.eps, replace
